class Api::V1::VideosController < ApplicationController
  before_action :set_video, only: [:show, :update, :destroy]

  # GET /api/v1/videos
  # GET /api/v1/videos.json
  def index
    @videos = Video.all
  end

  # GET /api/v1/videos/1
  # GET /api/v1/videos/1.json
  def show
  end

  # POST /api/v1/videos
  # POST /api/v1/videos.json
  def create
    @video = Video.new(video_params)

    if @video.save
      render :show, status: :created, location: @video
    else
      render json: @video.errors, status: :unprocessable_entity
    end
  end

  # PATCH/PUT /api/v1/videos/1
  # PATCH/PUT /api/v1/videos/1.json
  def update
    if @video.update(video_params)
      render :show, status: :ok, location: @video
    else
      render json: @video.errors, status: :unprocessable_entity
    end
  end

  # DELETE /api/v1/videos/1
  # DELETE /api/v1/videos/1.json
  def destroy
    @video.destroy
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_video
      @video = Video.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def video_params
      params.fetch(:api_v1_video, {})
    end
end
